package mobi.hami.huapin.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import mobi.hami.huapin.base.Result;
import mobi.hami.huapin.model.CreateNoteAudit;
import mobi.hami.huapin.service.impl.ManagementUGCServiceImpl;
import mobi.hami.huapin.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/ugc", produces = "application/json")
@Api(description = "供管理后台-纸条UGC管理相关api")
public class ManagementUgcController {

    private static Integer startPageNum = 1;
    private static Integer pageSize = 10;

    @Autowired
    private ManagementUGCServiceImpl managementUGCServiceImpl;


    /**
     * UGC管理-列表
     * @param mm
     * @return
     */
    @RequestMapping(value = "/list.do", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "UGC管理-列表", notes = "{\n" +
            "  \"pageSize\": 每页容量,\n" +
            "  \"startPageNum\": 页码,\n" +
            "  \"comtent\": \"纸条内容\",\n" +
            "  \"start_create_time\": \"创建时间搜索区间开始时间\",\n" +
            "  \"end_create_time\": \"创建时间搜索区间结束时间\",\n" +
            "  \"status\": \"审核状态: 0未审核，1，失败，2审核通过\",\n" +
            "  \"audit_user_id\": \"审核者id\"\n" +
            "}")
    @ApiResponses({
            @ApiResponse(code = 200, message = "{\n" +
                    "  \"success\": true,\n" +
                    "  \"data\": {\n" +
                    "    \"startPageNum\": 页码,\n" +
                    "    \"totalNum\": 总记录数,\n" +
                    "    \"pageSize\": 每页容量,\n" +
                    "    \"totalPageNum\": 总页数,\n" +
                    "    \"list\": [\n" +
                    "      {\n" +
                    "        \"id\": 该记录的主键盘,\n" +
                    "        \"comtent\": \"内容\",\n" +
                    "        \"user_id\": 创建者id,\n" +
                    "        \"create_time\": \"创建时间\",\n" +
                    "        \"audit_user_id\": 审核者id,\n" +
                    "        \"audit_time\": 审核时间,\n" +
                    "        \"audit_comment\": 审核备注,\n" +
                    "        \"status\": 审核状态: 0未审核，1，失败，2审核通过,\n" +
                    "        \"user_address_id\": 空间ID\n" +
                    "      }\n" +
                    "    ]\n" +
                    "  }\n" +
                    "}")
    })
    public Result CreateNoteAudits(@RequestBody Map<String, Object> mm) {
        HashMap<String, Object> data = new HashMap<String, Object>();
        if (null != mm && null != mm.get("startPageNum")) {
            startPageNum = new Integer(String.valueOf(mm.get("startPageNum")));
        }
        if (null != mm && null != mm.get("pageSize")) {
            pageSize = new Integer(String.valueOf(mm.get("pageSize")));
        }
        Page page = PageHelper.startPage(startPageNum, pageSize, true).reasonable(true);
        List<CreateNoteAudit> list = managementUGCServiceImpl.selectWitchParam(mm);
        PageInfo<CreateNoteAudit> pi = new PageInfo<>(list);
        int totalRecord = (int) page.getTotal();
        data.put("totalNum", totalRecord);
        int totalPageNum = (totalRecord + pageSize - 1) / pageSize;
        data.put("totalPageNum", totalPageNum);
        data.put("startPageNum", startPageNum);
        data.put("pageSize", pageSize);
        data.put("list", list);
        return Results.successWithData(data);
    }



    /**
     * 纸条审核拒绝操作
     */
    @RequestMapping(value = "/refuse.do", method = RequestMethod.POST)
    @ApiOperation(value = "拒绝操作", notes = "")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "id为审核记录主键", example = "6", paramType = "query", required = true, dataType = "int"),
            }
    )
    @ApiResponses({
            @ApiResponse(code = 200,message = "{\n" +
                    "  \"success\": true或者false,\n" +
                    "  \"status\": 0成功1失败,\n" +
                    "  \"msg\": \"提示消息\"\n" +
                    "}")
    })
    public Result refuse(Integer id){
        return managementUGCServiceImpl.refuse(id);
    }




    /**
     * 纸条审核采纳操作
     */
    @RequestMapping(value = "/agree.do", method = RequestMethod.POST)
    @ApiOperation(value = "采纳操作", notes = "")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "id为审核记录主键", example = "6", paramType = "query", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "user_address_id", value = "该纸条诉属空间id", example = "6", paramType = "query", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "creator_id", value = "创建者id", example = "6", paramType = "query", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "comtent", value = "纸条内容", example = "6", paramType = "query", required = true, dataType = "String"),
            }
    )
    public Result agree(Integer id,Integer user_address_id,Integer creator_id,String comtent){
        return managementUGCServiceImpl.agree(id,user_address_id,creator_id,comtent);
    }




}
